/**********************************************************************************
 * Copyright (c) 2012 - 2012,  parallel, All right reserved
 * Title: com.adc.parallel.util  LogUtil.java 
 * @author shen  shenqiao2012@163.com 
 *  2012-11-21 下午3:05:51 
 *********************************************************************************/


package com.adc.parallel.util;

import java.io.File;
import java.util.List;

import com.adc.parallel.constants.SysConstants;
import com.adc.quicktools.file.FileControl;


/**
 * 
 * Description: for this component, used to write log
 * @author shen  shenqiao2012@163.com
 */
public class LogUtil {
	
	/**
	 * 
	 * Description: write process log per day
	 * author:  shen
	 * @param contentList
	 * @return boolean
	 */
	public static boolean writeProcessLogPerDay(List<String> contentList) {
		String logFileName=SysConstants.getProcessLogName();
		String filePath=SysConstants.getLogBase().concat("histories/").concat(logFileName);
		return FileControl.writeAsLine(filePath, contentList, true, null);
	}
	
	/**
	 * 
	 * Description: write persistent file by identity 
	 * author:  shen
	 * @param identity
	 * @param contentList
	 * @return boolean
	 */
	public static boolean writePersistentFile(String identity,List<String> contentList) {
		String persistFileName=SysConstants.getPersistentFileName(identity);
		String bakPersistFileName=SysConstants.getPersistentFileName(
				identity.concat("-"+FileControl.getCurrentTimeString("yyyyMMddHHmm")));
		String filePath=SysConstants.getLogBase().concat(persistFileName);
		String bakFilePath=SysConstants.getLogBase().concat("persistBak/").concat(bakPersistFileName);
		File file=new File(filePath); 
		if (file.exists()) {
			FileControl.copyFile(filePath, bakFilePath);
			file.delete();
		}
		return FileControl.writeAsLine(filePath, contentList, false, null);
	}

}
